package day03;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Scanner;

/**
 * 输入某人生日，格式为"yyyy-MM-dd"，输出到现在为止经过了多少周。
 * @author Bonnie
 *
 */
public class Test03 {
    public static void main(String[] args) throws ParseException {
        Scanner scan = new Scanner(System.in);
        String regex = "\\d{4}-\\d{2}-\\d{2}";
        System.out.println("请输入生日(格式yyyy-MM-dd):");
        String writeIn = scan.next();
        scan.close();
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        if (writeIn.matches(regex)){
            //符合规范
            Date date = format.parse(writeIn);
            long answer = (System.currentTimeMillis() - date.getTime()) / 7L / 24L / 60 / 60 / 1000;
            System.out.println("截止今日，您已出生" + answer + "周");
        }else {
            System.out.println("输入有误!");
        }
    }

}
